package com.bidepan.scope;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestOrder {
//    单例bean：在IoC容器创建时创建，在IoC容器中只有一个对应的实例
    @Test
    public void demo1(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean-scope.xml");
        Order order1 = context.getBean("order1", Order.class);
        System.out.println(order1);
        Order order2 = context.getBean("order1", Order.class);
        System.out.println(order2);
    }

//    多例bean：在context调用getBean()时创建，在IoC中可有多个实例
    @Test
    public void demo2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean-scope.xml");
        Order order1 = context.getBean("order2", Order.class);
        System.out.println(order1);
        Order order2 = context.getBean("order2", Order.class);
        System.out.println(order2);
    }
}
